Expression Trigger Example
Overview
Triggers are automatic actions that react to any change in data and run immediately after that, when a condition is met, to activate a process or execute an expression.
The following section illustrates an example regarding a trigger that executes an expression.
Note
- Triggers will be executed over changes made through Bizagi's regular use (e.g., via expressions such as
setXpath
or through the Work Portal).- Triggers will NOT execute for changes made directly in the database.
- For virtualized entities, triggers will execute if changes are made through Bizagi's regular use. However, they will NOT execute if changes happen externally in the source table and Bizagi is updated via virtualization.
Example
Consider a scenario in a retail store where a registered Customer becomes a VIP if they make a purchase of at least 1,000 USD.
For this example, the following data model has been defined:
When the Purchase process is started, a Customer will have a list of purchased products:
To create the trigger that sets the customer as VIP:
- Go to the entity to be evaluated, in this case, the Purchase entity.
- Expand it, right-click the Triggers node, and select New trigger.
Configuring the Trigger
-
Set Display Name and Condition
In the configuration window, set a display name and specify a condition to determine when the trigger is evaluated and launched. -
Define the Condition Rule
Select or create a condition rule to determine when the trigger is executed.
In this example, the trigger executes when the total value of a purchase is 1,000 USD or greater.
As a best practice, manage the value as a vocabulary definition. -
Define the Expression
Once the condition is set, define the expression to execute.
In this example, an expression sets the Customer attribute called VIP astrue
.- Select Execute an expression and click the plus button to create a new expression.
-
Save the Trigger
Once created, click OK to save your changes.
Viewing the Trigger
After creation, the trigger appears in the list when selecting the Triggers node:
Whenever a purchase exceeds the specified value, the trigger will set the Customer as VIP:
Data Mapping
When the trigger launches an expression, the expression is executed on the record that triggered it.
This means the record itself is the context of the expression.
For the example above:
- All the Customer's information is available, as well as the products.
- Everything navigable through XPath from the Purchase record can be obtained.